﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.DB;
using System.Data.SqlClient;
using MaxLeaf.Common;
using System.Data;

namespace MaxLeaf.DAL.K2W
{
    public class ICStockBillCheckedDAL : IDALAction
    {
        W2K.OeSalesOrderDAL.FromType mFromType = new W2K.OeSalesOrderDAL.FromType();
        public int Add(DBAccess dbOrgK3Con, DBAccess dbDestWebReadCon, DBAccess dbDestWebWriteCon, string strKeyValue)
        {
            mFromType =GetFromType( dbOrgK3Con,strKeyValue);
            return  new K2W.OeSalesOrderDAL().Add(dbOrgK3Con, dbDestWebReadCon, dbDestWebWriteCon, strKeyValue, mFromType);
        }

        private W2K.OeSalesOrderDAL.FromType GetFromType(DBAccess dbOrgK3Con, string strFInterID)
        {
            string strSql = "select FTranType,Frob from ICStockBill where FInterID=@FInterID";
            DataRow drData=  dbOrgK3Con.GetDataFirstRow(strSql, new SqlParameter[]{
                    new SqlParameter("@FInterID",strFInterID)                    
                }) ;
            if (drData != null)
            {
                if (CvtFunc.ToInt(drData["FTranType"]) == 21 && CvtFunc.ToInt(drData["Frob"]) == -1)
                {
                    return W2K.OeSalesOrderDAL.FromType.RedICStockBillChecked;
                }
                else if (CvtFunc.ToInt(drData["FTranType"]) == 29 && CvtFunc.ToInt(drData["Frob"]) == -1)
                {
                    return W2K.OeSalesOrderDAL.FromType.RedOtherICStockBillChecked;
                }
            }
            
            return W2K.OeSalesOrderDAL.FromType.BlueICStockBillChecked;
        }
        public int Update(DBAccess dbOrgK3Con, DBAccess dbDestWebReadCon, DBAccess dbDestWebWriteCon, string strKeyValue)
        {
            mFromType = GetFromType(dbOrgK3Con, strKeyValue);
            return new K2W.OeSalesOrderDAL().Update(dbOrgK3Con, dbDestWebReadCon, dbDestWebWriteCon, strKeyValue, mFromType);
        }
        public void Delete(DBAccess dbOrgK3Con, DBAccess dbDestWebReadCon, DBAccess dbDestWebWriteCon, string strKeyValue)
        {
            mFromType = GetFromType(dbOrgK3Con, strKeyValue);
            new K2W.OeSalesOrderDAL().Delete(dbOrgK3Con, dbDestWebReadCon, dbDestWebWriteCon, strKeyValue, mFromType);
        }
    }

}
